//
var vue_login = new Vue({
    el: '#login_app',
    data: {
        form: {
            username: '',
            password: '',
            rememberMe: false
        },
        redirectUrl: '/dashboard' // 默认重定向到dashboard
    },
    created: function () {
        // 从URL参数中获取重定向地址
        const urlParams = new URLSearchParams(window.location.search);
        const redirect = urlParams.get('redirect');
        if (redirect) {
            this.redirectUrl = decodeURIComponent(redirect);
        }
    },
    methods: {
        handleLogin: function () {
            var f = this.form || {}
            // console.log('f->', f)
            if (!f.username) return this.$message('用户名不能为空！');
            if (!f.password) return this.$message('密码不能为空！');
            api_loginCheck(f, function (res) {
                if (res.code == 200) {
                    var rd = res.data || {}
                    window.localStorage.setItem('yumoAiAdmin:userInfo', JSON.stringify(rd))
                    window.location.href = this.redirectUrl;
                    this.$message.success('登录成功！');
                } else {
                    this.$message.error('登录失败，请稍后再试！', res.message);
                }
            }.bind(this))
        },
    }
})